<input id="status" name="status" type="hidden" value="{$params.status}"/>
<input id="p" name="p" type="hidden" value="{$p}" />
<table class="table table-bordered">
    <thead>
      <tr>
        <th width="6%">车主ID</th>
        <th width="8%">姓名</th>
      <if condition="$params['status'] gt 1">
        <th width="9%">电话</th>
      </if>
        <th>车型</th>
        <th width="6%" >所在地</th>
      <if condition="$params['status'] eq 1">
        <th width="15%">提交时间</th>
      </if>
      <if condition="$params['status'] eq 2">
        <th width="15%" >下次跟踪时间</th>
        <th width="7%">跟踪类型</th>
      </if>
      <if condition="$params['status'] eq 8">
        <th width="12%">预约时间</th>
        <th width="15%">预约地点/门店</th>
      </if>
        <if condition="$params.status neq 8"><th width="15%">渠道来源</th></if>
        <?php if($params['auth'] && $params['status']>1):?>
        <th width="8%">客服</th>
        <?php endif;?>
        <if condition="$params.status eq 3">
            <th width="10%">失败原因描述</th>
        </if>
        <th width="5%">操作</th>
      </tr>
    </thead>
    <tbody>
      <volist name="list" id="vo" key="k">
        <tr>
          <td>{$vo.owner_id}</td>
          <td>{$vo.seller_name}</td>
        <if condition="$params['status'] gt 1">
          <td>{$vo.phone}</td>
        </if>
          <td>{$vo.car_model}</td>
          <td>{$vo.location_area}</td>
        <if condition="$params['status'] eq 1">
          <td>{$vo.posttime}</td>
        </if>
        <if condition="$params['status'] eq 2">
          <td>{$vo.next_trace_time}</td>
            <td><?php echo C('TRACE_TYPE.'.$vo['trace_type']);?></td>
        </if>
        <if condition="$params['status'] eq 8">
            <td>{$vo.reserve_time}</td>
            <td>{$vo.address}</td>
        </if>
        <if condition="$params.status neq 8">
          <td>
            <if condition="$vo.comefrom neq ''">
              <?php if(empty($vo['comefrom_url'])):?>
                <?php echo $show_from[$vo['comefrom']];?>
              <?php else: ?>
                <a href="{$vo.comefrom_url}" target="_blank" rel="noreferrer"><?php echo $show_from[$vo['comefrom']];?></a>
              <?php endif;?>
            <else/>
                未知
            </if>
          </td>
         </if>
        <?php if($params['auth'] && $params['status']>1 ):?>
          <td>{$vo.server_name}</td>
        <?php endif;?>
          <if condition="$params.status eq 3"><td>{$vo.reserve_remark}</td></if>
          <td>
              <?php if($params['status']==1 || ( $params['status']==2 && $params['emp_id'] == $vo['service_id'])):?>
                <?php if($vo['trace_type']==1 || $vo['trace_type']==2 || ($vo['trace_type']==3 && $vo['delay_status']<3) ):?>
                    <a href="javascript:reserve({$vo.owner_id});"> 处理</a>
                <?php elseif($vo['trace_type']==3 && $vo['delay_status'] > 2 && $vo['delay_status']!=5):?>
                    <a class="not-point" href="#" > 预约</a>
                <?php else:?>
                    <a href="javascript:reserve({$vo.owner_id});"> 预约</a>
                <?php endif;?>
              <?php endif;?>
              <?php if($params['auth'] && $params['status'] == 2):?>
                <a href="javascript:void(0);" onclick="fenpei(<?php echo $vo['owner_id'];?>);">分配</a>
              <?php endif;?>
            <?php if($params['status']==3 || $params['status']==8):?>
              <a href="/CarOwner/reserveInfo?id={$vo.owner_id}" target="_blank">查看</a>
            <?php endif;?>
          </td>
        </tr>
      </volist>
    </tbody>
  </table>
  <div class="pageFaye"><div class="pager">{$page}</div><div class="clear"></div></div>

<div class="deparHover" style="height: 200px;">
    <h4>分配客服</h4>
    <label>
        <select name="service_id" id="service_id" style="float: right;width: 360px;">
            <option value="0">请选择客服</option>
            <?php foreach($kfs as $kf):?>
            <option value="{$kf.emp_id}">{$kf.real_name}</option>
            <?php endforeach;?>
        </select>
        分配给：
    </label>
    <div class="deparBtn">
        <input type="button" value="确定" class="deparQue" id="fenpeiQueding">
        <input type="button" value="取消" id="fenpeiQuxiao">
    </div>
</div>


<script>
    $("#checker").select2();
    function reserve(owner_id){
        var params = {
            'id':owner_id
        }
        $.post("/CarOwner/check_reserve_status", params, function (data) {
            if (data.code != 200) {
                shibai_alert(data.msg);
                return false;
            }
            setTimeout("openwin('/CarOwner/ownerInfo?id=" + owner_id + "')", 500);
        }, "json");
    }

    function fenpei(oid){
        var bg = $(".yunBei");
        var pp = $(".deparHover");
        var qd = $("#fenpeiQueding");
        var qx = $("#fenpeiQuxiao");

        $("#service_id").select2();
        bg.show();
        pp.show();
        $([bg,qd,qx]).each(function(i,n){
            $(n).unbind('click');
        });
        qx.click(hide_pp);
        bg.click(hide_pp);
        qd.click(function(){
            var service_id = $("#service_id").val();
            $.post("/CarOwner/assignServer",{"owner_id":oid, "service_id":service_id},function(data){
                if(data.code!=200){
                    shibai_alert(data.msg, 1500);
                    return false;
                }
                btn_alert("分配成功",1000,function(){
                    window.location.reload();
                });
            },"json");
        });
        function hide_pp(){
            bg.hide();
            pp.hide();
            bg.unbind('click');
        }
    }
    function openwin(url) {
        var a = document.createElement("a");
        a.setAttribute("href", url);
        a.setAttribute("target", "_blank");
        a.setAttribute("id", "openwin");
        document.body.appendChild(a);
        a.click();
    }

</script>